package com.simple.crawler.connect.ext;

import com.simple.crawler.connect.ResponseConverter;
import com.simple.crawler.utils.IOUtils;
import org.springframework.stereotype.Component;

import java.io.ByteArrayOutputStream;
import java.io.InputStream;

@Component
public class ByteArrayResponseConverter implements ResponseConverter<byte[]> {

    @Override
    public byte[] doConvert(InputStream in) throws Exception {
        ByteArrayOutputStream bos = IOUtils.read(in, new ByteArrayOutputStream());
        if (bos == null) {
            return new byte[0];
        }
        return bos.toByteArray();
    }

}
